﻿#ifndef TRANSLATOR_H
#define TRANSLATOR_H

#include <QStringList>
#include <QHash>
#include "literals/word.h"
#include "expression.h"

class Expression;
class Bracket;

class NCA_EXPORT Translator
  {
  public:
    Translator();

    QString expToString( const Expression &);
    QString sentenceToString( const Sentence &);

    // hey - maybe we do static versions of those?
    bool stringToExp( const QString &, Expression &exp );
    bool stringToSentence( const QString &, Sentence &sen );

    void registerName(QString sName, Word::Type type);
    int clearRegisteredNames();
    void setDefaultRegisteredNames();

  private:
    enum ParserError {
      PE_BRACKET,
      PE_DELTA_LABELS,
      PE_FUNCTION_ARGUMENTS,
      PE_OPERATOR_LABEL,
      PE_COEFFICIENT,
      PE_GENERAL_ERROR,
      PE_NO_ERROR = 0
    };

    QHash<QString,Word::Type> _registeredNames;

    int parseDeltaLabels(const QString &str, int i, QString &lOne, QString &lTwo);
    int parseCoefficient(int i, const QString &str, double &coeff);
    int parseBracket(int i, const QString &str, Bracket &bracket);
    int parseArguments(int i, const QString &str, QStringList &args);
  };

#endif // TRANSLATOR_H
